/*
 * queue
 *
 *  Created on: May 29, 2013
 *      Author: Gugg
 */

#include <stdio.h>
#include <stdlib.h>
#include "queue.h"

struct QueueRecord {
	int capacity;
	int front;
	int rear;
	int size;
	ElementType *Array;
};

int QueueSize(Queue Q) {
	return Q->size;
}

int IsEmpty(Queue Q) {
	return Q->size == 0;
}

int IsFull(Queue Q) {
	return Q->size == Q->capacity;
}

Queue CreateQueue(int MaxElements) {
	Queue Q;
	Q = malloc(sizeof(struct QueueRecord));
	if (Q == null)
		Error("");

	Q->Array = malloc(sizeof(ElementType) * MaxElements);
	if (Q->Array == NULL)
		Error("");
	Q->Capacity = MaxElements;
	MakeEmpty(Q);
	return Q;
}

void DisposeQueue(Queue Q) {
	if (Q != NULL) {
		free(Q->Array);
		free(Q);
	}
}
void MakeEmpty(Queue Q) {
	Q->Size = 0;
	Q->Front = 1;
	Q->Rear = 0;
}
void Enqueue(ElementType X, Queue Q) {
	if (IsFull(Q))
		Error("Full queue");
	else {
		Q->Size++;
		Q->Rear = Succ(Q->Rear, Q);
		Q->Array[Q->Rear] = X;
	}
}
